using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ACME.Northwind.DataTransfer;
using ACME.Northwind.Service.Interfaces;
using ACME.Northwind.MockProxy.EventArgs;

namespace ACME.Northwind.MockProxy
{
	/// <summary>
	/// The service implementation for Region object
	/// </summary>
	public partial class RegionService : IRegionService
	{
		#region IRegionService Members

		/// <summary>
		/// Run the mock for the select by the primary key
		/// </summary>
		public RegionDTO SelectByPrimaryKey(int regionid)
		{
			RegionPrimaryKeyEventArgs eventArgs = new RegionPrimaryKeyEventArgs(regionid);
			this.OnMockRegionSelectByPrimaryKey(eventArgs);
			return eventArgs.ReturnValue;
		}

		/// <summary>
		/// Run the mock for select all
		/// </summary>
		public List<RegionDTO> RunSelect()
		{
			RegionRunSelectEventArgs eventArgs = new RegionRunSelectEventArgs();
			this.OnMockRegionRunSelect(eventArgs);
			return eventArgs.ReturnValue;
		}

		/// <summary>
		/// Run the mock for select with LINQ
		/// </summary>
		public List<RegionDTO> RunSelect(string linq)
		{
			RegionRunSelectLINQEventArgs eventArgs = new RegionRunSelectLINQEventArgs(linq);
			this.OnMockRegionRunSelectLINQ(eventArgs);
			return eventArgs.ReturnValue;
		}

		/// <summary>
		/// Run the mock for paged select
		/// </summary>
		public PagedQueryResults<RegionDTO> RunSelect(int pageIndex, int pageSize, bool ascending, string sortColumn, string linq)
		{
			RegionRunSelectPagedEventArgs eventArgs = new RegionRunSelectPagedEventArgs(pageIndex, pageSize, ascending, sortColumn, linq);
			this.OnMockRegionRunSelectPaged(eventArgs);
			return eventArgs.ReturnValue;
		}

		/// <summary>
		/// Return a list of related Territory objects
		/// </summary>
		public List<TerritoryDTO> GetTerritoryList(RegionDTO item)
		{
			RegionDTOEventArgs eventArgs = new RegionDTOEventArgs(item);
			this.OnMockGetTerritoryList(eventArgs);
			List<TerritoryDTO> retval = new List<TerritoryDTO>();
			retval.AddRange(eventArgs.ReturnDTOList.Select(x => (TerritoryDTO)x));
			return retval;
		}

		/// <summary>
		/// Persists a single item
		/// </summary>
		public bool Persist(RegionDTO dto)
		{
			RegionPersistEventArgs eventArgs = new RegionPersistEventArgs(dto);
			this.OnMockRegionPersist(eventArgs);
			return eventArgs.ReturnValue;
		}

		/// <summary>
		/// Persists a list
		/// </summary>
		public bool Persist(List<RegionDTO> list)
		{
			RegionPersistEventArgs eventArgs = new RegionPersistEventArgs(list);
			this.OnMockRegionPersist(eventArgs);
			return eventArgs.ReturnValue;
		}

		/// <summary>
		/// Delete a single item
		/// </summary>
		public bool Delete(RegionDTO dto)
		{
			RegionDeleteEventArgs eventArgs = new RegionDeleteEventArgs(dto);
			this.OnMockRegionDelete(eventArgs);
			return eventArgs.ReturnValue;
		}

		#endregion

		#region Region Events

		partial void GetSelectByPrimaryKey();

		/// <summary>
		/// The event for the SelectByPrimaryKey method
		/// </summary>
		public event EventHandler<RegionPrimaryKeyEventArgs> MockRegionSelectByPrimaryKey;

		/// <summary>
		/// Raises the OnMockRegistrationCodeSelectByPrimaryKey event
		/// </summary>
		protected virtual void OnMockRegionSelectByPrimaryKey(RegionPrimaryKeyEventArgs e)
		{
			if (this.MockRegionSelectByPrimaryKey != null)
				this.MockRegionSelectByPrimaryKey(this, e);
		}

		/// <summary>
		/// The event for the RunSelect method
		/// </summary>
		public event EventHandler<RegionRunSelectEventArgs> MockRegionRunSelect;

		/// <summary>
		/// Raises the OnMockRunSelect event
		/// </summary>
		protected virtual void OnMockRegionRunSelect(RegionRunSelectEventArgs e)
		{
			if (this.MockRegionRunSelect != null)
				this.MockRegionRunSelect(this, e);
		}

		/// <summary>
		/// The event for the RunSelectLINQ method
		/// </summary>
		public event EventHandler<RegionRunSelectLINQEventArgs> MockRegionRunSelectLINQ;

		/// <summary>
		/// The event for the OnMockRunSelectLINQ method
		/// </summary>
		protected virtual void OnMockRegionRunSelectLINQ(RegionRunSelectLINQEventArgs e)
		{
			if (this.MockRegionRunSelectLINQ != null)
				this.MockRegionRunSelectLINQ(this, e);
		}

		/// <summary>
		/// The event for the RunSelectPaged method
		/// </summary>
		public event EventHandler<RegionRunSelectPagedEventArgs> MockRegionRunSelectPaged;

		/// <summary>
		/// The event for the OnMockRunSelectPaged method
		/// </summary>
		protected virtual void OnMockRegionRunSelectPaged(RegionRunSelectPagedEventArgs e)
		{
			if (this.MockRegionRunSelectPaged != null)
				this.MockRegionRunSelectPaged(this, e);
		}

		/// <summary>
		/// The event for the GetTerritoryList method
		/// </summary>
		public event EventHandler<RegionDTOEventArgs> MockGetTerritoryList;

		/// <summary>
		/// The event for the OnMockGetTerritoryList method
		/// </summary>
		protected virtual void OnMockGetTerritoryList(RegionDTOEventArgs e)
		{
			if (this.MockGetTerritoryList != null)
				this.MockGetTerritoryList(this, e);
		}

		/// <summary>
		/// The event for the Persist method
		/// </summary>
		public event EventHandler<RegionPersistEventArgs> MockRegionPersist;

		/// <summary>
		/// Raises the OnMockPersist event
		/// </summary>
		protected virtual void OnMockRegionPersist(RegionPersistEventArgs e)
		{
			if (this.MockRegionPersist != null)
				this.MockRegionPersist(this, e);
		}

		/// <summary>
		/// The event for the Delete method
		/// </summary>
		public event EventHandler<RegionDeleteEventArgs> MockRegionDelete;

		/// <summary>
		/// Raises the OnMockDelete event
		/// </summary>
		protected virtual void OnMockRegionDelete(RegionDeleteEventArgs e)
		{
			if (this.MockRegionDelete != null)
				this.MockRegionDelete(this, e);
		}

		#endregion

	}
}
